   
package com.mycjj.android.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.mycjj.android.R;
import com.mycjj.android.bean.ArticleDetailBaseBean;
import com.mycjj.android.bean.ArticleDetailBaseBean.ArticleDetailBean;
import com.mycjj.android.http.ProjectHttpRequestImpl;
import com.mycjj.android.http.ProjectHttpRequestInterface;
import com.mycjj.android.util.Preferences;


public class My_NewsDetailActivity extends BaseActivity{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_me_news_detail);
		initHeader();
		init();
		initData();
	}
	
	private ImageView mHeaderLeftImageview;
	private Button mHeaderRightButton;
	private TextView mHeaderTitleTextView;

	private void initHeader() {
		mHeaderLeftImageview = (ImageView) findViewById(R.id.header_left_button);
		mHeaderLeftImageview.setImageResource(R.drawable.back);
		mHeaderRightButton = (Button) findViewById(R.id.header_right_button);
		mHeaderRightButton.setVisibility(View.GONE);
		mHeaderTitleTextView = (TextView) findViewById(R.id.header_title_textview);
		mHeaderTitleTextView.setText("资讯详情");
		mHeaderLeftImageview.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				My_NewsDetailActivity.this.finish();
			}
		});
	}
	
	private TextView tv_title,tv_time,tv_store_name,tv_content;
	private ImageView iv_pic;
	private WebView webView;
	private void init(){
		Intent intent = getIntent();
		if(intent != null){
			id = intent.getStringExtra("id");
		}
		tv_title = (TextView)findViewById(R.id.tv_title);
		tv_time = (TextView)findViewById(R.id.tv_time);
		tv_store_name = (TextView)findViewById(R.id.tv_store_name);
		tv_content = (TextView)findViewById(R.id.tv_content);
		tv_content.setMovementMethod(new ScrollingMovementMethod());
		iv_pic = (ImageView)findViewById(R.id.iv_pic);
		webView = (WebView)findViewById(R.id.webview);
		webView.getSettings().setDefaultTextEncodingName("UTF-8");
//		webView.getSettings().setUseWideViewPort(true); 
//		webView.getSettings().setDisplayZoomControls(false);
		webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);  //就是这句
		webView.getSettings().setLoadWithOverviewMode(true);
		webView.setBackgroundColor(0); 
	}
	private String id;
	private void initData(){
		request = new ProjectHttpRequestImpl(this, true);
		RequestParams params = new RequestParams();
		params.put("client_id",ProjectHttpRequestInterface.client_id_key);
		params.put("token", Preferences.getSharedPreferences(this, "user_token", ""));
		params.put("id", id);
		request.requestSystemArticleDetailWithDoneHandler("", params, new AsyncHttpResponseHandler(){
			
			@Override
			public void onSuccess(String content) {
				ArticleDetailBaseBean baseBean = dataManager.getArticleDetailBaseBean();
				if(baseBean != null){
					if(baseBean.getCode() == 200){
						ArticleDetailBean bean = baseBean.getData();
						if(bean != null){
							tv_title.setText(bean.getArticle_title());
							tv_time.setText(bean.getArticle_time());
//							tv_store_name.setText("");
//							tv_store_name.setVisibility(View.GONE);
//							imageLoader.displayImage(bean.getCover(), iv_pic);
//							tv_content.setText(bean.getArticle_content());
							webView.loadDataWithBaseURL("",bean.getArticle_content(), "text/html", "UTF-8","");
						}
					}else{
						Toast.makeText(My_NewsDetailActivity.this, baseBean.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}else{
					Log.e("mark", "ArticleDetailBaseBean is null!");
				}
			}
		});
	}
}
